﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Maticsoft.Web
{
    public partial class Default : System.Web.UI.Page
    {
        protected string _AdvStr;
        protected string _AdvNum;
        protected void Page_Load(object sender, EventArgs e)
        {
            GetTitleMeta();
            BindAdvert();
            BindNewProduct();
            Bind1();
            Bind2();
            Bind3();
        }

        protected void GetTitleMeta( )
        {
            BLL.WebSiteConfig configBLL = new BLL.WebSiteConfig();
            Model.WebSiteConfig configModel = configBLL.GetModel(1);
            Title = configModel.SiteName;
            MetaKeywords = configModel.KeyWords;
            MetaDescription = configModel.Description;
        }

        protected void BindNewProduct()
        {
            BLL.Products proBLL = new BLL.Products();
            DataSet ds = proBLL.GetList(4, "IsHot=1 and IsHid=0 and IsActive=1", "orderNo desc");
            Repeater1.DataSource = ds.Tables[0].DefaultView;
            Repeater1.DataBind();
        }

        protected void Bind1( )
        {
            BLL.Products proBLL = new BLL.Products();
            DataSet ds = proBLL.GetList(4, "categoryId in(select categoryId from Categorys where parentId=1) and IsTop=1 and IsHid=0 and IsActive=1", "orderNo desc");
            RepeaterP1.DataSource = ds.Tables[0].DefaultView;
            RepeaterP1.DataBind();
        }

        protected void Bind2( )
        {
            BLL.Products proBLL = new BLL.Products();
            DataSet ds = proBLL.GetList(4, "categoryId in(select categoryId from Categorys where parentId=2) and IsTop=1 and IsHid=0 and IsActive=1", "orderNo desc");
            RepeaterP2.DataSource = ds.Tables[0].DefaultView;
            RepeaterP2.DataBind();
        }

        protected void Bind3( )
        {
            BLL.Products proBLL = new BLL.Products();
            DataSet ds = proBLL.GetList(4, "categoryId in(select categoryId from Categorys where parentId=3) and IsTop=1 and IsHid=0 and IsActive=1", "orderNo desc");
            RepeaterP3.DataSource = ds.Tables[0].DefaultView;
            RepeaterP3.DataBind();
        }

        protected void BindAdvert()
        {
            //BLL.AdvertPics advBLL = new BLL.AdvertPics();
            //DataSet ds = advBLL.GetList("AdvertId=1 and IsActive=1 order by OrderNo asc");
            //Repeater2.DataSource = ds.Tables[0].DefaultView;
            //Repeater2.DataBind();
            BLL.AdvertPics advBLL = new BLL.AdvertPics();
            DataSet ds = advBLL.GetList("AdvertId=1 and IsActive=1 order by OrderNo asc");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                _AdvNum = ds.Tables[0].Rows.Count.ToString();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    int j = i + 1;
                    _AdvStr += "img" + j + " = new Image(); img" + j + ".src = '/uploadfiles/ads/"+ds.Tables[0].Rows[i]["pic"]+"';";
                    _AdvStr += "url" + j + " = new Image(); url" + j + ".src = '" + ds.Tables[0].Rows[i]["url"] + "';";
                    _AdvStr += "txt" + j + " = new Image(); txt" + j + ".txt = '';";
                }
            }
        }
    }
}